VMS Help  —  PASCAL  Data Types, Structured Types, RECORD
  A record is a group of components (called fields) that can be of
  various  data  types.   Each record component may contain one or
  more data items.

  Syntax:

     [[PACKED]] RECORD [[field-list]] END
     END

  If field-list is not specified, an empty record is created.  The
  following is an example of a record type:

     RECORD
     Part     : INTEGER;
     Received : RECORD
                   Month : ( Jan, Feb, Mar, Apr, May, June,
                            Jul, Aug, Sep, Oct, Nov, Dec );
                   Day   : 1..31;
                   Year  : INTEGER;
                   END;
     END;

1  –  Field list

  The syntax for a field-list is as follows:

  { {{field-identifier},... : [[attribute-list]] type};...
            [[; variant-clause]] [[;]] variant-clause [[;]] }

  The 'field-identifier' is the name of a field.

  The 'attribute-list' is one or more  optional  identifiers  that
  provide additional information about the field.

  The 'type' is the type of the corresponding field.  A field  can
  be of any type.

  The 'variant-clause' is the variant part of a record.  A variant
  can  contain  different  types  or  amounts of data at different
  times during program execution.  The syntax for a variant clause
  is as follows:

   CASE { [[tag-identifier : ]] [[attribute-list]]
            tag-type-identifier}| discriminant-identifier } OF
            {{case-label-list} : (field-list)};...
          [[ [[;]] OTHERWISE (field-list)]]

  The 'tag-identifier' is the name of  the  tag  field.   The  tag
  field is all of the elements between the reserved words CASE and
  OF.

  The 'attribute-list' is one or more  optional  identifiers  that
  provide additional information about the variant.

  The 'tag-type-identifier' is the type  identifier  for  the  tag
  field.

  The  'discriminant-identifier'  is  the  name  of   the   formal
  discriminant  of  a schema type.  The value of the corresponding
  actual discriminant selects the active variant.  Once you select
  the variant by discrimination, you cannot change it again.

  The 'case-label-list' consists of one or more constant values of
  the  tag field type either separated by commas.  A case constant
  is either a single constant value (for example, 1) or a range of
  values (for example, 5..10).

  The 'field-list' consists of the names, types, and attributes of
  one or more fields.  At the end of a field list, you can specify
  another variant clause.  The field-list can be empty.

  'OTHERWISE' is equivalent to a case label list that contains tag
  values  (if any) not previously used in the record.  The variant
  labeled  with  OTHERWISE  is  the  current  variant   when   the
  tag-identifier  has  a  value  that does not occur in any of the
  case label lists.

  The following is an example of a variant record:

     RECORD
     Part : 1..9999;
     CASE On_Order : Boolean OF
            TRUE  : ( Order_Quantity : INTEGER;
                      Price          : REAL );
            FALSE : ( Rec_Quantity   : INTEGER;
                      Cost           : REAL );
     END;

  In this  example,  the  last  two  fields  in  the  record  vary
  depending  on  whether  the part is on order.  Records for which
  the value of the tag-identifier On_Order is  TRUE  will  contain
  information  about  the  current  order;  those  for which it is
  FALSE, about the previous shipment.

2  –  Standard record constructor

  Record constructors are lists of values  that  you  can  use  to
  initialize a record.

  Syntax:

     [[data-type]] [ [[{{component},... : component-value};... ]]
        [[{CASE [[tag-identifier :]] tag-value OF
           [{{component},... : component-value};... ]
           OTHERWISE ZERO [[;]] }]] ]

  The 'data_type' specifies the constructor's data type.   If  you
  use  the  constructor  in the executable section or in the CONST
  section, a data-type identifier is required.  Do not use a  type
  identifier   in   initial-state   specifiers  elsewhere  in  the
  declaration section or in nested constructors.

  The 'component' specifies a  field  in  the  fixed-part  of  the
  record.   Fields in the constructor do not have to appear in the
  same order as they do in the type definition.  (If  you  choose,
  you  can  specify  fields  from  the variant-part as long as the
  fields do not overlap.)

  The 'component-value' specifies a value same data  type  as  the
  component.  These values are compile-time values; if you use the
  constructor in the executable section, you can also use run-time
  values.

  'CASE' provides a constructor  for  the  variant  portion  of  a
  record.   If the record contains a variant, its constructor must
  be the last component in the constructor list.

  The 'tag-identifier' specifies the tag-identifier of the variant
  portion  of  the  record.   This is only required if the variant
  part contained a tag-identifier.

  The 'tag-value' determines which component  list  is  applicable
  according to the variant portion of the record.

  'OTHERWISE ZERO' sets all remaining components to  their  binary
  zero  value.   If  you  use  OTHERWISE ZERO, it must be the last
  component in the constructor.

  When you specify constructors for a record that contains  nested
  records,  specify  the  type of the outermost record, but do not
  specify the type of the constructors for any nested records.

  The following are examples  of  record  variables  and  possible
  standard record constructors:
  Example:

     TYPE
        Player_Rec = RECORD
           Wins   : INTEGER;
           Losses : INTEGER;
           Percentage : REAL;
           END;

     VAR
        Player1 : Player_Rec VALUE [Wins: 18; Losses: 3;
                                    Percentage: 21/18]

  This record constructor  appears  in  the  variable  declaration
  section,  so  the constructor type is optional, and compile-time
  values are required.

  Example:

     TYPE
        Player_Rec = RECORD
           Wins   : INTEGER;
           Losses : INTEGER;
           Percentage : REAL;
           END;

     VAR
        Player1, Player2 : Player_Rec;

     {In the executable section}
     Player1 := Player_Rec[Wins:18; Losses: y; Percentage: Y+18/18];

  This record constructor appears in the  executable  section,  so
  the  constructor  type  is required and run-time expressions are
  legal.

3  –  Nonstandard record constructor

  Syntax:

     [[data-type]] ([[{component-value},...]]
        [[tag-value, {component-value},...]])

  The 'data_type' specifies the constructor's data type.   If  you
  use  the  constructor  in  the  executable  section, a data-type
  identifier is required.  Do not use a type identifier in the VAR
  or VALUE sections, or for a nested constructor.

  The 'component-value' specifies a compile-time value of the same
  data  type  as  the  component.   The compiler assigns the first
  value to the first record component, the  second  value  to  the
  second component, and so forth.

  The 'tag-value' specifies a value for the  tag-identifier  of  a
  variant  record  component.   The value that you specify as this
  component of the constructor determines the types and  positions
  of  the  remaining  component  values  (according to the variant
  portion of the type definition).

  The following is an example of a record variable and a  possible
  nonstandard record constructor:

     Rec : RECORD
           Person  : VARYING [30] OF CHAR;
           Address : RECORD
                     Number : INTEGER;
                     Street : VARYING [30] OF CHAR;
                     Zip    : 0..9999;
                     END;
           Age     : 0..150:
           END;

  ('Blaise Pascal', (1623, 'Pensees Street', 91662), 39)
Close Help